#!/usr/bin/env python
# -*- coding: utf-8 -*-

# @Time     :2020/11/28
# @Author   :Changshu
# @File     :Exercise_501.py
# 501. 二叉搜索树中的众数

# 给定一个有相同值的二叉搜索树（BST），找出 BST 中的所有众数（出现频率最高的元素）。
# 假定 BST 有如下定义：
#
# 结点左子树中所含结点的值小于等于当前结点的值
# 结点右子树中所含结点的值大于等于当前结点的值
# 左子树和右子树都是二叉搜索树

'''
class TreeNode:
	def __init__(self,x):
		self.val=x
		self.left=None
		self.right=None

base = -2147483648
count = 0
maxCount = 0
res = []

def update(x: int):
	if x == base:
		count += 1
	else:
		if count > maxCount != 0:
			res.clear()
			res.append(base)
			maxCount = count
		else:
			if count == maxCount and maxCount != 0:
				res.append(base)
				maxCount = count
		count = 1


def findMode(self, root: TreeNode) -> list:
	return res
'''
'''

class Solution:
	def __init__(self):
		self.base = -2147483648
		self.count = 0
		self.maxCount = 0
		self.res = []

	def update(self,x: int):
		if x == self.base:
			self.count += 1
		else:
			if self.count > self.maxCount != 0:
				self.res.clear()
				self.res.append(self.base)
				self.maxCount=self.count
			else:
				if self.count==self.maxCount and self.maxCount!=0:
					self.res.append(self.base)
					self.maxCount = self.count
			self.count = 1

	def findMode(self, root: TreeNode) -> list:
		return self.res
'''
'''
if __name__ == '__main__':
	solution=Solution()
	l=[3,4,6,7,7,7,8,8,9,10,11,11,11,11,12,13,13,13,14,15]
	for x in l:
		solution.update(x)
	print(solution.res)
'''

